/**
 * 
 */
package Test;

import java.util.ArrayList;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;

import business.Schedule;
import data.Job;
import data.Volunteer;



/**
 * This class performs basic unit testing functionality for the Volunteer class.
 * Note: The only method currently being tested in this version is the Volunteer
 * class constructor method.
 * 
 * @author Stephen Amos
 * @version 1.0
 */
public class VolunteerTest extends TestCase {
	/**
	 * Volunteer.
	 */
	private Volunteer test_volunteer;
	/**
	 * Firstname.
	 */
	private String firstname;
	/**
	 * Lastname.
	 */
	private String lastname;
	/**
	 * Username.
	 */
	private String username;
	/**
	 * Password.
	 */
	private String password;
	/**
	 * Phone.
	 */
	private String phone;
	/**
	 * Email.
	 */
	private String email;
	/**
	 * Date of birth.
	 */
	private String dob; //Date is depreciated - consider using
										//alternative solutions.
	
	/**
	 * This method instantiates a Volunteer object, and populates it with
	 * a set of test field values. 
	 */
	@Before
	public void setUp() throws Exception {
		firstname = "john";
		lastname = "doe";
		username = "anonymous";
		password = "p@ss";
		phone = "111-111-1234";
		email = "web@master.com";
		dob = "1/1/1990";
		
		test_volunteer = new Volunteer(firstname, lastname, username, 
				password, phone, email, dob);
		
	}

	/**
	 * This method tests a Volunteer object's constructor.
	 * 
	 * 1) Test whether the Volunteer object's firstname field has been created
	 * successfully with the correct data.
	 * 2) Test whether the Volunteer object's surname field has been created
	 * successfully with the correct data.
	 * 3) Test whether the Volunteer object's username field has been created
	 * successfully with the correct data.
	 * 4) Test whether the Volunteer object's password field has been created
	 * successfully with the correct data.
	 * 5) Test whether the Volunteer object's phone field has been created
	 * successfully with the correct data.
	 * 6) Test whether the Volunteer object's email field has been created
	 * successfully with the correct data.
	 * 7) Test whether the Volunteer object's data field has been created
	 * successfully with the correct data.
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the constructor has failed to create a Volunteer object
	 * as intended.
	 */
	@Test
	public void testVolunteer() {
		String test_firstname = test_volunteer.getFirstname();
		String test_surname = test_volunteer.getSurname();
		String test_username = test_volunteer.getUsername();
		String test_password = test_volunteer.getPassword();
		String test_phone = test_volunteer.getPhone();
		String test_email = test_volunteer.getEmail();
		String test_date = test_volunteer.getDob();
		
		assertEquals("Firstname assertion failed.", test_firstname.equals(firstname), true);
		assertEquals("Surname assertion failed.", test_surname.equals(lastname), true);
		assertEquals("Username assertion failed.", test_username.equals(username), true);
		assertEquals("Password assertion failed.", test_password.equals(password), true);
		assertEquals("Phone assertion failed.", test_phone.equals(phone), true);
		assertEquals("Email assertion failed.", test_email.equals(email), true);
		assertEquals("Date assertion failed.", test_date.equals(dob), true);
	}
	
	/**
	 * Tests whether the equals method for the Volunteer class functions
	 * as intended.
	 * 
	 * 1) This assertion passes if the objects are equal. 
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the equals method has failed to function as intended
	 * for the Volunteer class.
	 */
	@Test
	public void testEquals() {
		String firstname = "John";
		String lastname = "Doe";
		String username = "anonymous";
		String password = "p@ss";
		String phone = "111-111-1234";
		String email = "web@master.com";
		String dob = "1/1/1990";
		
		Volunteer test_volunteer2 = new Volunteer(firstname, lastname, username, 
				password, phone, email, dob);
		
		assertEquals("Equals assertion failed.", test_volunteer.equals(test_volunteer2), true);
	}
	
	/**
	 * This test determines whether the compareTo() method functions as intended
	 * for the Volunteer class.
	 * 
	 * 1) Tests whether the compared object is alphabetically equal.
	 * 2) Tests whether the compared object is alphabetically higher.
	 * 3) Tests whether the compared object is alphabetically lower.
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the compareTo() method has failed to function as intended
	 * for the Volunteer class.
	 */
	@Test
	public void testCompare() {
		String firstname = "John";
		String username = "anonymous";
		String password = "p@ss";
		String phone = "111-111-1234";
		String email = "web@master.com";
		String dob = "1/1/1990";
		
		Volunteer test_volunteer2 = new Volunteer(firstname, "aaa", username, 
				password, phone, email, dob);
		
		Volunteer test_volunteer3 = new Volunteer(firstname, "zzz", username, 
				password, phone, email, dob);
		
		assertEquals("compareTo assertion failed.", test_volunteer.compareTo(test_volunteer) == 0, true);
		assertEquals("compareTo assertion failed.", test_volunteer.compareTo(test_volunteer2) > 0, true);
		assertEquals("compareTo assertion failed.", test_volunteer.compareTo(test_volunteer3) < 0, true);
	}
	
	/**
	 * Tests whether the toString() method for a Scheduler object functions
	 * as intended.
	 * 
	 * 1) Assert whether the toString() method for the Scheduler class functions as intended.
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the toString() method has failed to function as intended
	 * for the Scheduler class.
	 */
	@Test
	public void testString() {
		String test_string = "john,,doe,,anonymous,,p@ss,,111-111-1234,,web@master.com,,1/1/1990,,false\n";
		assertEquals("toString assertion failed.", test_volunteer.toString().equals(test_string), true);
	}
	
	
	/**
	 * 
	 * 
	 * author Krisnil Gounder
	 * version March 5th, 2011
	 * 
	 * This test method adds a new job where the leader status is false and then a 
	 * volunteer is assigned as a leader.
	 * 
	 */
	@Test
	public void testLeader() {
		Schedule schedule = new Schedule();
		ArrayList<Volunteer> loadedVolunteers = new ArrayList<Volunteer>();

		String lmaName = "testLmaName";;
		String jobName = "testJobName";
		String lmaPhone = "0262421344";
		String trailLocation = "testTrailLocation";
		int grade = 4;
		int difficulty = 2;			
		String description = "testDescription";
		String date = "03/11/2011";
		String time = "01:03PM";
		int size = 6;
		
		schedule.addJob(new Job(jobName,lmaPhone, trailLocation, grade,
				difficulty, description, date, time, lmaName, size,
				false, false, loadedVolunteers));
		
		assertEquals("The leader status should be false", test_volunteer.isLeader(), false);
		test_volunteer.setLeader(true);
		assertEquals("The leader status should be true now", test_volunteer.isLeader(), true);
	}

}
